package com.gqz.qrcode.api.factory;

import com.gqz.common.core.domain.R;
import com.gqz.qrcode.api.RemoteQrcodeService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 远程qrcode回退
 *
 * @author gqz20
 * @date 2023/02/11
 */
@Component
@Slf4j
public class RemoteQrcodeFallback implements FallbackFactory<RemoteQrcodeService> {

    /**
     * 二维码服务回退工厂
     *
     * @param cause 导致
     * @return {@link RemoteQrcodeService}
     */
    @Override
    public RemoteQrcodeService create(Throwable cause) {
        return new RemoteQrcodeService() {
            @Override
            public R getQRCodeBase64(String content) {
                log.info(cause.getMessage());
                return R.fail(cause.getMessage());
            }

            @Override
            public void getQRCode(HttpServletResponse response, String content) {

            }

            @Override
            public R decryptQRCode(String content) {
                log.info(cause.getMessage());
                return R.fail(cause.getMessage());
            }
        };
    }
}
